import { getProjectLx, getWaitCount, getProjectYsData, getSummaryData } from '@/apilist/Project'

const state = {
    //立项
    projectLx: {
        list: [],
        total: 0,
        status_list: []
    },

    waitCount: {
        lx: 0,
        ys: 0,
        js: 0,
        cw: 0,
        xm: 0,
        xz: 0,
    },
    //预算
    projectYs: {
        list: [],
        total: 0,
    },
    //结算
    projectJs: {
        list: [],
        total: 0,
    },
    //汇总数据
    summary: {
        list: [],
        total: 0,
        yearList: [],
        deptList: [],
        companyList: [],
        staffList: [],
        customerList: [],
        projectList: [],
    },

    searchStatus: 0,
}

const mutations = {
    //获取项目数据
    getProjectLxMutations(state, data) {
        state.projectLx.list = data.data
        state.projectLx.total = data.total
        state.projectLx.status_list = data.status_list
    },
    //获取待审批个数
    getProjectWaitCountMutations(state, data) {
        state.waitCount.lx = data.lx
        state.waitCount.ys = data.ys
        state.waitCount.js = data.js
        state.waitCount.cw = data.cw
        state.waitCount.xm = data.xm
        state.waitCount.xz = data.xz
    },
    //预算,结算数据
    getProjectYsMutations(state, data) {
        state.projectYs.list = data.data
        state.projectYs.total = data.total
    },

    //汇总数据
    getSummaryDataMutations(state, data) {
        state.summary.list = data.data
        state.summary.total = data.total
        state.summary.yearList = data.yearList
        state.summary.deptList = data.deptList
        state.summary.companyList = data.companyList
        state.summary.staffList = data.staffList
        state.summary.customerList = data.customerList
        state.summary.projectList = data.projectList
    },

    //预算,结算数据//getProjectJsMutations
    getProjectJsMutations(state, data) {
        state.projectJs.list = data.data
        state.projectJs.total = data.total
    },

    SET_SEARCH_STATUS(state, status) {
        state.searchStatus = status;
    },

}

const actions = {
    //获取项目数据
    async getProjectLxActions(ctx, data) {
        let res = await getProjectLx(data)
        ctx.commit('getProjectLxMutations', res.data)
    },

    //获取待审批个数
    async getProjectWaitCountActions(ctx, data) {
        let res = await getWaitCount(data)
        ctx.commit('getProjectWaitCountMutations', res.data)
    },

    //获取预算数据
    async getProjectYsActions(ctx, data) {
        let res = await getProjectYsData(data)
        ctx.commit('getProjectYsMutations', res.data)
    },
    //获取结算数据
    async getProjectJsActions(ctx, data) {
        let res = await getProjectYsData(data)
        console.log('js...', res.data)
        ctx.commit('getProjectYsMutations', res.data)
    },

    //获取结算数据
    async getSummaryDataActions(ctx, data) {
        let res = await getSummaryData(data)
            //console.log('js...',res.data)
        ctx.commit('getSummaryDataMutations', res.data)
    },

    async setStatus(ctx, status) {
        ctx.commit('SET_SEARCH_STATUS', status)
    }

}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}